﻿function MapClass() {
    this.map = new Array();
    this.add = function (key, value) {
        for (var i = 0; i < this.map.length; i++) {
            if (this.map[i].key === key) {
                this.map[i].value = value;
                return;
            }
        }

        this.map[this.map.length] = new struct(key, value);

    };
    this.get = function (key) {
        for (var i = 0; i < this.map.length; i++) {
            if (this.map[i].key === key) {
                return this.map[i].value;
            }
        }

        return null;
    };
    //Delete 
    this.del = function (key) {
        var v;
        for (var i = 0; i < this.map.length; i++) {
            v = this.map.pop();
            if (v.key === key)
                continue;

            this.map.unshift(v);
        }
    };
    this.count = function () {
        return this.map.length;
    };
    this.empty = function () {
        return this.map.length <= 0;
    }
    //返回array数组
    this.toArray = function () {
        return this.map;
    }
    this.getk = function (x) {
        return this.map[x].value;
    }
    //排序,array数组
    this.sort = function () {
        this.map.sort(function (a, b) {
            rv = 0;
            if ((Number(a.value.zLayer) - Number(b.value.zLayer)) == 0) {
                rv = Number(a.value.zOrder) - Number(b.value.zOrder);
            }
            else {
                rv = Number(a.value.zLayer) - Number(b.value.zLayer);
            }
            return rv;
        });
    }
    this.sort_layer = function () {
        this.map.sort(function (a, b) { return b.value.zLayer - a.value.zLayer; });
    }
    this.sort_des = function () {
        this.map.sort(function (a, b) { return b.value.zOrder - a.value.zOrder; });
    }
}
function struct(key, value) {

    this.key = key;
    this.value = value;

} 